package tests.suite.tests.xspf4x
{
	import com.gdcnano.libs.xspf4x.XSPF4X;
	
	import flexunit.framework.Assert;

	public class XSPF4XTest
	{
		// XSPFXML.title
		private static const TITLE:String = "Sample playlist";
		// XSPFXML.creator
		private static const CREATOR:String = "Jane Doe";
		// XSPFXML.info
		private static const INFO:String = "http://example.com/myplaylists";
		// XSPFXML.annotation
		private static const ANNOTATION:String = "My favorite songs";
		// XSPFXML.license
		private static const LICENSE:String = "http://creativecommons.org/licenses/by/1.0/";
		// XSPFXML.image
		private static const IMAGE:String = "http://example.com/img/mypicture";
		// XSPFXML.identifier
		private static const IDENTIFIER:String = "magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C";
		
		// !IMPORTANT Should be equal to <track> elements count in <tracklist>
		private static const PLAYLIST_LENGTH:int = 3;
		
		private static const XML_WITH_DIFFERENT_NS:XML = 
			<playlist version="1" xmlns="http://example.com/">
				<title>Sample playlist</title>
				<creator>Jane Doe</creator>
				<info>http://example.com/myplaylists</info>
				<trackList>
				<track>
				  <location>http://ru100379426/music/Compilations/Trance In Motion (vol.23)/01 Waiting (Original Mix).mp3</location>
				  <title>Waiting (Original Mix)</title>
				  <creator>Dash Berlin Feat. Emma Hewitt</creator>
				  <album>Trance In Motion (vol.23)</album>
				</track>
				<track>
				  <location>http://ru100379426/music/Compilations/Trance In Motion (vol.23)/02 You And I (Dash Berlin Mix).mp3</location>
				  <title>You And I (Dash Berlin Mix)</title>
				  <creator>Median</creator>
				  <album>Trance In Motion (vol.23)</album>
				</track>
				<track>
				  <location>http://ru100379426/music/Compilations/Trance In Motion (vol.23)/03 Spellbound (Original Mix).mp3</location>
				  <title>Spellbound (Original Mix)</title>
				  <creator>Tritonal Feat. Christina Soto</creator>
				  <album>Trance In Motion (vol.23)</album>
				</track>
			  </trackList>
			</playlist>;
			
		private static const XSPFXML:XML = 
			<playlist version="1" xmlns="http://xspf.org/ns/0/">
				<title>Sample playlist</title>
			
				<creator>Jane Doe</creator>
				<info>http://example.com/myplaylists</info>
				<annotation>My favorite songs</annotation>
				<location>http://example.com/myplaylists/myplaylist</location>
				<identifier>magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C</identifier>
				<image>http://example.com/img/mypicture</image>
				<date>2005-01-08T17:10:47-05:00</date>
				<license>http://creativecommons.org/licenses/by/1.0/</license>
				<attribution>
					<identifier>http://bar.com/secondderived.xspf</identifier>
					<location>http://foo.com/original.xspf</location>
			  	</attribution>
			  	<link rel="http://foaf.example.org/namespace/version1">http://socialnetwork.example.org/foaf/mary.rdfs</link>
			  	<meta rel="http://example.org/key">value</meta>
			  	<extension application="http://example.com">
					<clip start="25000" end="34500"/>
			  	</extension>
			
				<trackList>
				<track>
				  <location>http://ru100379426/music/Compilations/Trance In Motion (vol.23)/01 Waiting (Original Mix).mp3</location>
				  <title>Waiting (Original Mix)</title>
				  <creator>Dash Berlin Feat. Emma Hewitt</creator>
				  <album>Trance In Motion (vol.23)</album>
				</track>
				<track>
				  <location>http://ru100379426/music/Compilations/Trance In Motion (vol.23)/02 You And I (Dash Berlin Mix).mp3</location>
				  <title>You And I (Dash Berlin Mix)</title>
				  <creator>Median</creator>
				  <album>Trance In Motion (vol.23)</album>
				</track>
				<track>
				  <location>http://ru100379426/music/Compilations/Trance In Motion (vol.23)/03 Spellbound (Original Mix).mp3</location>
				  <title>Spellbound (Original Mix)</title>
				  <creator>Tritonal Feat. Christina Soto</creator>
				  <album>Trance In Motion (vol.23)</album>
				</track>
			  </trackList>
			</playlist>;
		
		private var _xspf:XSPF4X;
		
		public function XSPF4XTest()
		{
		}
		
		[Test]
		public function canParseXMLAndCreateObject():void
		{
			try 
			{
				_xspf = new XSPF4X(XML_WITH_DIFFERENT_NS);
			}
			catch (e:ArgumentError)
			{
				Assert.assertNull(_xspf);
			}
			
			_xspf = new XSPF4X(XSPFXML);
			// Check properties
			Assert.assertEquals(TITLE, _xspf.title);
			
			Assert.assertEquals(ANNOTATION, _xspf.annotation);
			
			Assert.assertEquals(CREATOR, _xspf.creator);
			
			Assert.assertEquals(IMAGE, _xspf.image);
			
			Assert.assertEquals(INFO, _xspf.info);
			
			Assert.assertEquals(LICENSE, _xspf.license);
			
			// As Flex SDK 3.2 doesn't support DateFormatter.parseDateString
			Assert.assertNull(_xspf.date);
			
			Assert.assertEquals(IDENTIFIER, _xspf.identifier);
			
			Assert.assertEquals(PLAYLIST_LENGTH, _xspf.trackList.length);
			
			
		}
	}
}